package com.huawei.struts.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.huawei.struts.service.IUserService;
import com.huawei.struts.service.imp.UserService;
import com.st.model.LjwUserT;

public class BaseAction extends DispatchAction {
	private IUserService userService;

	public ActionForward goSuccess(String tipInfo, String returnUrl,
			HttpServletRequest request, HttpServletResponse response,ActionMapping mapping) {
		request.setAttribute("info", tipInfo);
		request.setAttribute("returnUrl", returnUrl);
		return mapping.findForward("goSuccess");
	}
	
	public ActionForward goFail(String tipInfo, String returnUrl,
			HttpServletRequest request, HttpServletResponse response,ActionMapping mapping) {
		request.setAttribute("info", tipInfo);
		request.setAttribute("returnUrl", returnUrl);
		return mapping.findForward("goFail");
	}
	

	public void downloadFile(String path, String fileName,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		File downFile = new File(path);
		response.setContentType("application/vnd.ms-excel");
		response.setHeader("Content-Disposition", "attachment; filename="
				+ fileName);
		response.addHeader("Cache-Control", "no-cache");
		InputStream blobStream = new FileInputStream(downFile);
		ServletOutputStream outStream = response.getOutputStream();
		byte[] buffer = new byte[10 * 1024];
		int nbytes = 0;
		while ((nbytes = blobStream.read(buffer)) != -1) {
			outStream.write(buffer, 0, nbytes);
		}
		outStream.flush();
		outStream.close();
		blobStream.close();
	}

}
